/**
 * 用户信息类
 */
package com.key;

import com.key.util.UserSystemData;

public class KeyChineseChessUserInfo {
	
	//用户等级和分数
	private int iNowUserRank = 0;
	private int iNowUserGrade = 0;
	
	/**
	 * 设置用户等级
	 * @param iRank 等级
	 */
	public synchronized void setUserRank(int iRank) {
		if(iRank > UserSystemData.RANK_LAST) {
			iNowUserRank = UserSystemData.RANK_LAST;
		} else if(iRank < UserSystemData.RANK_FIRST) {
			iNowUserRank = UserSystemData.RANK_FIRST;
		} else {
			iNowUserRank = iRank;
		}
	}
	
	/**
	 * 设置用户分数
	 * @param iGrade 分数
	 */
	public synchronized void setUserGrade(int iGrade) {
		if(iGrade < 0) {
			iNowUserGrade = 0;
		} else {
			iNowUserGrade = iGrade;
		}
	}
	
	public int getUserRank() {
		return iNowUserRank;
	}
	
	public int getUserGrade() {
		return iNowUserGrade;
	}
	
	/**
	 * 用户加分
	 * @param iGrade
	 * @return
	 */
	public synchronized boolean plusUserGrade( int iGrade ) {
		iNowUserGrade += iGrade;
		return true;
	}
	
	/**
	 * 用户减分
	 * @param iGrade
	 * @return
	 */
	public synchronized int subUserGrade(int iGrade) {
		if(iNowUserGrade-iGrade < 0) {
			return -1;
		}
		iNowUserGrade -= iGrade;
		return 0;
	}
	
	/**
	 * 用户加等级
	 */
	public synchronized void plusAUserRank() {
		if(iNowUserRank == UserSystemData.RANK_LAST) {
			iNowUserRank = UserSystemData.RANK_LAST;
		} else {
			iNowUserRank += 1;
		}
	}
	
	/**
	 * 用户等级减小
	 */
	public synchronized void subAUserRank() {
		if(iNowUserRank == UserSystemData.RANK_FIRST) {
			iNowUserRank = UserSystemData.RANK_FIRST;
		} else {
			iNowUserRank -= 1;
		}
	}
}
